package com.zbkj.service.dividend.event;

import com.zbkj.common.model.order.Order;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

/**
 * 分红池事件发布服务
 */
@Service
public class DividendPoolEventPublisher implements ApplicationEventPublisherAware {

    private ApplicationEventPublisher eventPublisher;

    @Override
    public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
        this.eventPublisher = applicationEventPublisher;
    }

    /**
     * 发布分红池变更事件
     */
    public void publishDividendChangeEvent(Integer userId, BigDecimal currentBalance, String description) {
        DividendPoolEvent event = DividendPoolEvent.createPoolEvent(userId, currentBalance, description);
        eventPublisher.publishEvent(event);
    }

    /**
     * 发布分红池分红事件
     */
    public void publishDividendEvent(Order order) {
        DividendEvent event = DividendEvent.createDividendEvent(order);
        eventPublisher.publishEvent(event);
    }
}